package com.heima.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.service.ApFollowBehaviorService;
import com.heima.common.constants.message.FollowBehaviorConstants;
import com.heima.model.behavior.dto.FollowBehaviorDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * Created by ZYJ on 2021/6/4 21:04
 */
@Component
@Slf4j
public class FollowBehaviorListener {
    @Autowired
    ApFollowBehaviorService apFollowBehaviorService;

    @KafkaListener(topics = FollowBehaviorConstants.FOLLOW_BEHAVIOR_TOPIC)
    public void receiverMessage(String message) {
        if (StringUtils.isNotBlank(message)) {
            log.info("收到关注行为消息==>{}", message);
            apFollowBehaviorService.
                    saveFollowBehavior(JSON.parseObject(message, FollowBehaviorDto.class));
            log.info("执行保存关注行为完成");
        }
    }
}
